//
//  MoreViewController.m
//  HuateVideo
//
//  Created by Tiger on 12-5-17.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "MoreViewController.h"
#import "SettingViewController.h"
#import "AboutViewController.h"
#import "AdviceViewController.h"
#import "LLViewController.h"
#import "SearchViewController.h"
@interface MoreViewController ()

@end

@implementation MoreViewController
-(void)dealloc{
    [tableArray release];
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        tableArray=[[NSMutableArray alloc] init];
        NSDictionary*dic=[NSDictionary dictionaryWithObjectsAndKeys:LS(@"设置"),@"title",@"setting.png",@"img", nil];
        [tableArray addObject:dic];
        dic=[NSDictionary dictionaryWithObjectsAndKeys:LS(@"意见反馈"),@"title",@"yijian.png",@"img", nil];
        [tableArray addObject:dic];
        dic=[NSDictionary dictionaryWithObjectsAndKeys:LS(@"关于我们"),@"title",@"about.png",@"img", nil];
        [tableArray addObject:dic];
        dic=[NSDictionary dictionaryWithObjectsAndKeys:LS(@"流量统计"),@"title",@"流量.png",@"img", nil];
        [tableArray addObject:dic];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    UIButton *searchBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    searchBtn.frame=CGRectMake(0, 0, 42, 31);
    [searchBtn setImage:[UIImage imageNamed:@"search.png"] forState:UIControlStateNormal];
    [searchBtn addTarget:self action:@selector(pushSearchView) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* searchBarItem=[[UIBarButtonItem alloc] initWithCustomView:searchBtn];    
    self.navigationItem.rightBarButtonItem=searchBarItem;
    [searchBarItem release];
    
    r=0;
    self.view.backgroundColor = TOOLBAR_TINTCOLOR;
    table=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 416) style:UITableViewStylePlain];
    table.backgroundColor=[UIColor clearColor];
    table.delegate=self;
    table.dataSource=self;
    table.separatorColor=LIGHT_COLOR;
    [self.view addSubview:table];
    [table release];
    
    UIView* v=[[UIView alloc] init];
    table.tableFooterView=v;
    [v release];
}

-(void)pushSearchView{
    SearchViewController *searchViewController = [[SearchViewController alloc]init];
    [self.navigationController pushViewController:searchViewController animated:YES];
    [searchViewController release];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationItem.title=LS(@"更多");
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [table deselectRowAtIndexPath:[NSIndexPath indexPathForRow:r inSection:0] animated:YES];
}
- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark table
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
     static   NSString* identify=@"cell";
    UITableViewCell*cell=[tableView dequeueReusableCellWithIdentifier:identify];
    if (cell==nil) {
        cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identify] autorelease];
    }
    cell.textLabel.textColor=[UIColor whiteColor];
    cell.textLabel.font=[UIFont systemFontOfSize:16];
    cell.textLabel.text=[[tableArray objectAtIndex:indexPath.row] objectForKey:@"title"];
    NSString* imgStr=[[tableArray objectAtIndex:indexPath.row] objectForKey:@"img"];
    cell.imageView.image=[UIImage imageNamed:imgStr];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    r=indexPath.row;
    
    self.navigationItem.title=LS(@"返回");
    switch (indexPath.row) {
        case 0:
        {
            SettingViewController* set=[[SettingViewController alloc] init];
            set.title=LS(@"设置");
            [self.navigationController pushViewController:set animated:YES];
            [set release];
        }
            break;
        case 1:
        {
            AdviceViewController* advice=[[AdviceViewController alloc] init];
            advice.title=LS(@"意见反馈");
            [self.navigationController pushViewController:advice animated:YES];
            [advice release];
        }
            break;
        case 2:
        {
            AboutViewController* about=[[AboutViewController alloc] init];
            about.title=LS(@"关于我们");
            [self.navigationController pushViewController:about animated:YES];
            [about release];
        }
            break;
        case 3:
        {
            LLViewController* ll=[[LLViewController alloc] init];
            ll.title=LS(@"流量统计");
            [self.navigationController pushViewController:ll animated:YES];
            [ll release];
        }
            break;
            
        default:
            break;
    }
}

@end
